<template>
  <div>
    <!-- 返利池查询 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      columnsRef="wkcRebateInvoiceAudit"
      :columns="columns"
      :isSelectColumn="false"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="(columns) => (this.columns = columns)"
    >
      <template slot="controls"> </template>
    </FilterTable>

    <Drawer :visible.sync="isClick" :title="modelName" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"  width="72%">
      <addModel :rowData="addData" @close="addClose" />
    </Drawer>

   <Drawer :visible.sync="isDetail" :title="'返利红票申请明细'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }" width="72%">
      <detailModel :rowData="detailData" @close="detailclose" />
    </Drawer>

    <BaseDialog :visible.sync="isFinanceReject" :title="'作废返利红票申请单'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <FinanceReject :list="rejectData" @close="financeRejectClose" />
    </BaseDialog>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList, invalidApplyRed } from '@/api/omFinanceP/RebateManage/RebateInvoiceAudit';
import { exportExcelFile } from '@/utils';
import addModel from './addModel';
import FinanceReject from './FinanceReject';
import detailModel from './detailModel';
export default {
  name: 'RebateInvoiceAudit',
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {
        applyStatus: 21571002,
        isAuditPage: 10041001,
      },
      formData: {},
      detailData: {},
      rejectData: {},
      addData: {},
      visible: false,
      isClick: false,
      isDetail: false,
            isFinanceReject: false,
      handleType: '',
      modelName: '',
    };
  },
  components: { addModel, detailModel ,FinanceReject},

  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
        financeRejectClose(val) {
      if (val) {
        this.isOpen = true;
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
      this.isFinanceReject = false;
    },
    detailclose(val) {
      this.isDetail = false;
      if (val) {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    addClose(val) {
      this.isClick = false;
      if (val) {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    async editHandle(data, type) {
      if (type === 1) {
        this.isClick = true;
        this.modelName = '返利红票申请审核';
        this.addData = data;
      }
      if (type === 2) {
        this.detailData = data;
        this.isDetail = true;
      }
      if (type === 3) {
       this.isFinanceReject=true;
       this.rejectData=data;
        // await this.$confirm('是否确认作废返利红票申请?', '提示', {
        //   confirmButtonText: '确认',
        //   cancelButtonText: '取消',
        //   type: 'warning',
        // })
        //   .then(async () => {
        //     let res = await invalidApplyRed(data);
        //     if (res.resultCode === 200) {
        //       this.$notify({
        //         title: '成功',
        //         message: ' 作废操作成功',
        //         type: 'success',
        //       });
        //       this.fetchParams = Object.assign({}, this.fetchParams);
        //     }
        //   })
        //   .catch(() => {});
      }
    },
    formatNumber(value) {
      value += '';
      if (value.slice(-1) === '.') return value;
      value = value.replace(/,\s+/g, '');
      const list = value.split('.');
      const prefix = list[0].charAt(0) === '-' ? '-' : '';
      let num = prefix ? list[0].slice(1) : list[0];
      let result = '';
      while (num.length > 3) {
        result = `, ${num.slice(-3)}${result}`;
        num = num.slice(0, num.length - 3);
      }
      if (num) {
        result = num + result;
      }
      return `${prefix}${result}${list[1] ? `.${list[1]}` : ''}`;
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '返利红票申请单号',
          fieldName: 'applyNo',
          placeholder: '请输入',
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'applyStatus',
          placeholder: '请选择',
          itemList: this.createDictList('2157').filter((item) => item.value == '21571002' || item.value == '21571005' || item.value == '21571003' || item.value == '21571007'),
          initialValue: 21571002,
        },
        {
          type: 'RANGE_DATE',
          label: '申请时间',
          fieldName: 'beginApplyDate|endApplyDate',
          dateType: 'exactdaterange',
          placeholder: '请选择',
        },
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 160,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" disabled={props.row.applyStatus !== 21571002} onClick={() => this.editHandle(props.row, 1)}>
                  审核
                </multiuse-button>
                <el-divider direction="vertical" />
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 2)}>
                  明细
                </multiuse-button>
                <el-divider direction="vertical" />
                <multiuse-button size="mini" type="text" disabled={props.row.applyStatus !== 21571003} onClick={() => this.editHandle(props.row, 3)}>
                  作废
                </multiuse-button>
              </div>
            );
          },
        },
        {
          title: '状态',
          dataIndex: 'applyStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2157'),
          render: (props) => {
            return <span>{this.createDictText(props.row.applyStatus, '2157')}</span>;
          },
        },
        {
          title: '返利红票申请单号',
          width: 160,
          dataIndex: 'applyNo',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '所属区域',
          dataIndex: 'areaName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商代码',
          width: 120,
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '申请人',
          dataIndex: 'applyPersonName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '申请时间',
          dataIndex: 'applyDate',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
          filter: true,
          filterType: 'input',
        },

        {
          title: '申请金额',
          dataIndex: 'totalApplyAmount',
          sorter: true,
          filter: true,
          precision: 2,
          numberFormat: true,
          align: 'right',
          filterType: 'input',
        },
        {
          title: '发票号',
          dataIndex: 'sapInvoiceNo',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '开票时间',
          dataIndex: 'sapInvoiceDate',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '开票金额',
          dataIndex: 'sapInvoiceAmount',
          sorter: true,
          filter: true,
          precision: 2,
          numberFormat: true,
          align: 'right',
          filterType: 'input',
        },
        {
          title: '申请原因',
          dataIndex: 'applyReason',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '审核意见',
          dataIndex: 'checkDesc',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
         {
          title: '作废原因',
          dataIndex: 'cancelReason',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ];
    },
  },
};
</script>
